/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.skipass;

import java.util.Calendar;

/**
 *
 * @author Neophron
 */
public class WorkDayCountPass implements Pass {

    private static final PassType TYPE = PassType.WORKDAYCOUNT;

    private final int id;

    private final TripCount maxCount;

    private int usedCount = 0;

    private WorkDayCountPass(int id, TripCount maxCount) {
        this.id = id;
        this.maxCount = maxCount;
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public PassType getType() {
        return TYPE;
    }

    @Override
    public boolean allowTrip(Calendar curDay) {
        if (usedCount < maxCount.getCount()
                && curDay.get(Calendar.DAY_OF_WEEK) <= Calendar.FRIDAY
                && curDay.get(Calendar.DAY_OF_WEEK) >= Calendar.MONDAY) {
            usedCount++;
            return true;
        }
        return false;
    }

    public static WorkDayCountPass createWorkDayCountPass(int id,
            TripCount maxCount) {
        return new WorkDayCountPass(id, maxCount);
    }

}
